package cn.jnetty.utils;

/**
 *
 *
 *
 * @author 猪哥亮
 * @email 1030681978@qq.com
 * @date 2020/3/15 17:07
 * 描述：断言工具类，用于对方法的传入参数进行校验，如果未通过则
 * 抛出{@code IllegalArgumentException}异常
 */
public final class Assert {
	/**
	 * 断言对象不为空
	 *
	 * @param obj
	 */
	public static void notNull(Object obj) {
		if (obj == null) {
			notNull(obj, "");
		}
	}

	/**
	 * 断言对象不为空
	 *
	 * @param obj
	 */
	public static void notNull(Object obj, String msg) {
		if (obj == null) {
			throw new IllegalArgumentException(msg);
		}
	}
	/**
	 * 断言对象不为空
	 *
	 * @param obj
	 */
	public static void notNull(Object obj, RuntimeException e) {
		if (obj == null) {
			throw e;
		}
	}
	/**
	 * 断言表达式为真
	 *
	 * @param expression
	 */
	public static void isTrue(boolean expression) {
		if (!expression) {
			isTrue(expression, "");
		}
	}

	/**
	 * 断言表达式为真
	 *
	 * @param expression
	 */
	public static void isTrue(boolean expression, String msg) {
		if (!expression) {
			throw new IllegalArgumentException(msg);
		}
	}
	public static void isTrue(boolean expression, RuntimeException e) {
		if (!expression) {
			throw e;
		}
	}
}